Trees in PoV and self-generating include files
I don't like www, sorry. Don't flame me for this ugly homepage
design... But there are some of these enerving "friends" who forced me
to set up this page. I hope, you will find it usefull.
Some time ago I made an include-file for povray that produces
trees. The idea was born in a discusion whether it is possible to do
recursion in pov or not. It's not possible, not directly... I found a
trick to let povray produce its own include files and to produce
nested while statements in this self-generated include files, which is
equal to recursion.
You may have a look at these three trees. They are made with my
include file (if you use xv, you should increase the gamma value, the
pics are rendered with for very bright displays...)
437481 bytes
368896 bytes
436673 bytes
The tree sources:
Here's the include file which makes those trees: selftree.inc.
Ah, sorry. This is a newer version of the include file (see below), if
you want to render these trees by yourself (they take VERY LONG time!),
take this older version: selftree.old.inc
Sorry, documentation is in german only. If you want to know, how to
use it, you can read this documentation (sorry, it's written in
german, too...): Postscript-Version LaTeX-File
The docs are not ready yet...
A note: In the docs most of the parameters are simple numbers. I
think, that is not flexible enough. So I changed the include file. Now
you can use komplex functions for nearly all parameters. If you look
at the include file, all values that are enclosed in parentheses
should work with functions, all other should be simple numbers or
names. Try some values and functions to see, which are good.
How does it work?
Simple...
PoVRay has these fance streams which you can use for printing some
informations to stdout, stderr... With the option -GDFILENAME you can
send this output to a file. Now: take a the debug stream (#debug
"string") and produce some output that you can use as inputfile for
pov. Do this from a source file, and then include this sourcefile into
your first source file and you got it... Let's say, we want to include
a nested while-statement. We can write it by ourself, or do this:
#declare depth = 3
#declare second = depth
#while (depth>0)
#debug "#while bla bla bla\n"
#debug "some code\n"
#declare depth = depth-1
#end
#while (second>0)
#debug "#end\n"
#declare second = second-1
#end
This produces the following output to the debug-stream:
#while bla bla bla
some code
#while bla bla bla
some code
#while bla bla bla
some code
#end
#end
#end
Combining this with all the nice string functions in pov or with other
streams, you can produce really fancy output-files, which can be used
for including in the same file, which produced them. So you can take the
code above in your scene file, and then, one line after this in the
same file you say #include "bla.inc". Then running pov with
+IYOURFILE.pov -GDbla.inc produces bla.inc from your debug statements
and includes it while parsing and producing it... Very powerfull...
How do I use it??
Simple...
In your Scene file:
- 1: Declare some of the variables described below
- 2: include selftree.inc
- 3: include the file produced by the output of selftree.inc
- 4: say object { OBJECTNAME }
Running povray:
povray +I YOURFILE.pov -GDmytrees.inc
mytrees.inc is the file, where the debug stream goes, and which you
can include in your scene file (step 3 above)
Here are all the variables and their defaultvalues, you can set:
- OBJECTNAME = "TREE"
name of the object, you can produce more than one tree in your
includefile by including selftree.inc multiple times. Then you
should declare OBJECTNAME with different values.
- USESTDTRUNK = "YES"
use the standard trunk? (Which is only a simple cone)
- TRUNKLEN = "5"
How long is the trunk? (FLOAT, >0)
- TRUNKBASER = "1"
The base radius of the trunk (FLOAT, >0)
- TRUNKCAPR = "0.5"
The cap radius of the trunk (FLOAT, >0)
- DEPTH = 4
The depth of the recursion to produce (INT, >0)
- BLEN = "5"
Length of the branches in the first recursion step (FLOAT, >0)
- LDIFF = "0"
divergence to blen (is randomly added to BLEN) (FLOAT, LDIFF> -BLEN)
- RADIUS = "0.5"
Radius of the branches in the first recursion step (FLOAT, >0)
- RADSCALE = "0.5"
how to scale the values for the branches between the recursion steps (FLOAT, >0)
- RDIFF = "0"
divergence for the branch radius (subtraceted) (FLOAT, |RDIFF| RECSCALE = "0.5"
how to scale all other values (FLOAT, >0)
- SLOPEANGLE = "45"
slope angle for the branches (FLOAT)
- SANGLEDIFF = "0"
divergnecy for the slope angle (added to SLOPEANGLE) (FLOAT)
- ANGLESCALE = "1"
how to scale the slope angle (FLOAT)
- NRBRANCHES = "4"
how many branches (this is not how many branches for the whole
tree, but for every branch. so if you say NRBRANCHES = 4 , evere
produced branch has 4 child branches up to the DEPTHs recursion (INT, >0)
- NRBDIFF = "0"
divergence for NRBRANCHES (added to NRBRANCHES) (FLOAT)
- NRBSCALEADD = "0"
how to scale NRBRANCHES (added to NRBRANCHES)(FLOAT)
- NRBSCALEMUL = "1"
how to scale NRBRANCHES (multiplied with NRBRANCHES)(FLOAT)
- BRANCHTOP = "1"
where to put the child branches (1 = allways at the top of their
parents, 0 = somewhere at their parents) (FLOAT, 0<=x<=1)
- LEAFINC = "NO"
have a leaf-include file? (STRING, YES|NO)
- NRLEAFINCS = 0
How many different leafs are in the include file? the names of
the leafobjects shoul be LEAFSHAPE_00, LEAFSHAPE_01... (INT, >=0)
- NRLEAFS = "0"
how many leafs per branch (INT, >=0)
- NRLDIFF = "0"
diverngence for NRLEAFS (wird zu NRLEAFS addiert)(INT, NRLDIFF> -NRLEAFS)
- ROTRANGE = "360"
how to rotate the branches around their parents. normaly the
range would go up to 360 degrees, but if you minimize this value,
you can produce some kind of wind to the tree (works not very good) (FLOAT, 0<=x<=360)
- RANDINIT_ROT = "0.1234"
Init-value for random stream for ROTRANGE (FLOAT)
- RANDINIT_LDIFF = "0.1234"
Init-value for random stream for LDIFF (FLOAT)
- RANDINIT_RDIFF = "0.1234"
Init-value for random stream for RDIFF (FLOAT)
- RANDINIT_SDIFF = "0.1234"
Init-value for random stream for SANGLEDIFF (FLOAT)
- RANDINIT_NRBDIFF = "0.1234"
Init-value for random stream for NRBDIFF (FLOAT)
- RANDINIT_NRLDIFF = "0.1234"
Init-value for random stream for NRLDIFF (FLOAT)
- RANDINIT_LEAFSELECT = "0.1234"
Init-value for random stream for selecting the different leafs (FLOAT)
- RANDINIT_LEAFTRANS = "0.1234"
Init-value for random stream for positioning the leafs (FLOAT)
- RANDINIT_LEAFROT = "0.1234"
Init-value for random stream for leaf rotation (FLOAT)
- RANDINIT_BT = "0.1234"
Init-value for random stream for BRANCHTOP (FLOAT)
- #default { pigment { color rgb <0.35, 0.16, 0.14> } }
define a default texture for the branches... You can also define
different textures for the braches in the different recursion
steps. For the texture for the trunk use #declare MOD_TR =
texture { bla bla bla } for the branches in the first recursion
step use MOD_0 = texture { bla bla bla } and so on. If the
textures are not defined, default texture is used.
I think, that's it. It's not ready all, but I'm working on it (having
no time... really). If you use it and publish your pics with it,
please remark who made this include file (and, if you like, let me
have a look at your Pictures). If you have any questions,
mail me
There some more tools I made for and with pov. I hope, they will
appear here anytime (too lazy...).
Have fun,
Stephan Kuhagen